package define

import "errors"

var (
	ERROR_COMMAND_FAIL    = errors.New("command failed")
	ERROR_SLOT_OVERFLOW   = errors.New("slot overflow")
	ERROR_RESPONSE_NOTPTR = errors.New("response input is not ptr")
)

const (
	OPERATE_CREATE = 0
	OPERATE_DELETE = 1
	OPERATE_MODIFY = 2
)

// constant bytes
const (
	STX  = 0x02 // 开始字节
	ETX  = 0x03 // 结束字节
	Inst = 0x10 // 插入字节
	OemH = 0x5B // OEM代码高位，设置地址时使用
	OemL = 0xA0 // OEM代码低位，设置地址时使用
)

// special bytes
const (
	SPECIAL_BYTES_STX          = 0x02
	SPECIAL_BYTES_ETX          = 0x03
	SPECIAL_BYTES_RESP_SUCCESS = 0x06
	SPECIAL_BYTES_INST         = 0x10
	SPECIAL_BYTES_RESP_FAIL    = 0x15
	SPECIAL_BYTES_16           = 0x16
)

// commands
const (
	CMD_SET_ADDR             = 0x01 // 设置控制器地址
	CMD_GET_STATUS           = 0x40 // 取状态
	CMD_OPEN_DOOR            = 0x2C // 开门
	CMD_NORMAL_OPEN          = 0x2D // 门常开
	CMD_CLOSE_DOOR           = 0x2E // 关门
	CMD_SYNC_TIME            = 0x07 // 时间同步
	CMD_SET_CONTROLLER_PARAM = 0x63 // 设置控制器参数
	CMD_SET_DOOR_PARAM       = 0x61 // 设置门的参数
	CMD_CLEAR_OPEN_TIME      = 0x0F // 清除门的全部开放时间
	CMD_ADD_OPEN_TIME        = 0x0D // 增加一个开放时间
	CMD_ADD_HOLIDAY          = 0x09 // 增加一个假日
	CMD_BATCH_ADD_HOLIDAY    = 0x0A // 增加一组假日
	CMD_CLEAR_HOLIDAY        = 0x0C // 删除全部假日
	CMD_CLEAR_CARD           = 0x17 // 清除所有卡
	CMD_CLEAR_EVENT_ALARM    = 0x3F // 清除报警记录
	CMD_CLEAR_EVENT_RECORD   = 0x35 // 清除刷卡记录
	CMD_RESET_CONTROLLER     = 0x04 // 控制器复位
	CMD_SET_ALARM            = 0x18 // 设置报警
	CMD_SET_FIRE_ALARM       = 0x19 // 设置火警
	CMD_LOCK_UNLOCK_DOOR     = 0x2F // 锁/解锁门
	CMD_GET_EVENT_RECORD     = 0x31 // 取刷卡记录
	CMD_GET_EVENT_ALARM      = 0x3A // 取报警记录
	CMD_ADD_CARD             = 0x62 // 增加卡
	CMD_GET_CARD             = 0x70 // 读取卡数据
	CMD_GET_MAX_CARD_IDX     = 0x7A // 获取使用的最大卡编号值（控制器的卡容量）
	CMD_TEST_CARD            = 0x7B // 卡号测试
	CMD_GET_VERSION          = 0x7C // 获取版本信息
)

const (
	EVENT_STATE_CARD_RECORD = 0x08
	EVENT_STATE_ALARM       = 0x10
	EVENT_STATE_CARD_STATE  = 0x20
)

const (
	OPEN_MODE_SINGLE_CARD               = 0x01
	OPEN_MODE_CARD_AND_BINDING_PASSWORD = 0x02
	OPEN_MODE_TIMING_OPEN               = 0x03
	OPEN_MODE_DOUBLE_CARD               = 0x04
	OPEN_MODE_TIMEING_ALARM             = 0x07
	OPEN_MODE_PASSWORD                  = 0x08
	OPEN_MODE_CARD_OR_DOOR_PASSWORD     = 0x09
	OPEN_MODE_FIRST_CARD                = 0x10
	OPEN_MODE_ANTI_QIANFAN              = 0x80
)

const (
	CARD_FLAG_ENABLE  = 1
	CARD_FLAG_DISABLE = 0
)

const (
	EVENT_NORMAL_NO_MORE     = iota //记录已经取完
	EVENT_NORMAL_CONTINUE           //记录已经取完
	EVENT_WARN_IDX_NOT_MATCH        //记录收发包的序列号不一致
	EVENT_ERROR_OCCUR               //记录收发包错误
)

const (
	ALARM_TYPE_DOOR          = 0x01
	ALARM_TYPE_OPEN_TOO_LONG = 0x02
	ALARM_TYPE_INVALID_CARD  = 0x04
	ALARM_TYPE_INVALID_TIME  = 0x08
)

const (
	SEND_COMMAND_RESULT_SUCCESS = iota
	SEND_COMMAND_RESULT_FAIL
)

const ( // todo 映射可以能有问题 38变成了门报警
	EVENT_CONTENTS = "Effective card,单卡识别,Invalid card,无效卡号,Timezone error,没有时段,Invalid Timezone,无效时段,PIN error,密码错误,Double Error,双卡识别错误,Entry repeat,重复进门,Exit repeat,重复出门,not open door,门未开报警,unknown 9,未定义9号事件,Exit access,出门,Entry access,进门,Card and Password Access,卡加密码开门,Open by Double Cards,双卡开门,Open by Password,密码开门,Free pass,无限制通行,Invalid Card entry,无效卡进入,Invalid card exit,无效卡出,Black entry,黑名单人员进入,Black exit,黑名单人员出,Entry by card & PIN,卡加密码进门,Exit by card & PIN,卡加密码出门,Entry by double card,双卡进门,Exit by double card,双卡出门,Entry by PIN,密码进门,Exit by PIN,密码出门,Entry by Free,自由进门,Exit by Free,自由出门,Reject Entry,禁止进门,Reject Exit,禁止出门,unknown 30,未定义30号事件,unknown 31,未定义31号事件,unknown 32,未定义32号事件,unknown 33,未定义33号事件,unknown 34,未定义34号事件,unknown 35,未定义35号事件,unknown 36,未定义36号事件,unknown 37,未定义37号事件,unknown 38,未定义38号事件,Reader Alarm,读卡器防护,Alarm A,报警A,Alarm B,报警B,Alarm C,报警C,Alarm D,报警D,unknown 44,未定义44号事件,unknown 45,未定义45号事件,unknown 46,未定义46号事件,Hostage taking,挟持报警,Tamper alarm,防拆报警,Duress alarm,潜反报警,Battery flat,未请假出门,DURESS ALARM,潜反报警,EMERGENCY ALARM,紧急报警,Hardware err,硬件错误,disconnect,没有连接,invalid Serial,无效序列号,Door alarm,门报警,Door open too long,开门时间太长,Door unlock,门没锁,Door release,出门按钮打开,Cards ready entry,多人预备进门,Cards ready exit,多人预备出门,Cards entry,多人进门,Cards exit,多人出门,Cards error,多人开门错误,Cards outtime,多人开门超时,unknown 66,未定义66号事件,unknown 67,未定义67号事件,unknown 68,未定义68号事件,unknown 69,未定义69号事件,unknown 70,未定义70号事件,unknown 71,未定义71号事件,Fire Alarm,火警,Other Door open,别门已开,unknown 74,未定义74号事件,Controller Start,控制器启动,Invalid door,无效门,unknown 77,未定义77号事件,unknown 78,未定义78号事件,unknown 79,未定义79号事件,unknown 80,未定义80号事件,unknown 81,未定义81号事件,unknown 82,未定义82号事件,unknown 83,未定义83号事件,unknown 84,未定义84号事件,unknown 85,未定义85号事件,Connected,连接,unknown 87,未定义87号事件,unknown 88,未定义88号事件,unknown 89,未定义89号事件,unknown 90,未定义90号事件,unknown 91,未定义91号事件,unknown 92,未定义92号事件,unknown 93,未定义93号事件,unknown 94,未定义49号事件,unknown 95,未定义95号事件,login,操作员登录,logout,操作员登出,Reset alarm,手动报警复位,SARS alarm,SARS报警,Open door,门开,Close door,门关"
)
